package com.oocl.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FormatInput {
	public static boolean isValid(String string){
		String[] strings = string.split("\\s+");
		if(isEmail(strings[2]) && isSex(strings[3]) && isBirth(strings[4])){
			return true;
		}else{
			return false;
		}
	}
	
	private static boolean isEmail(String string){
		String reString1 = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
		Pattern p = Pattern.compile(reString1);
		Matcher m = p.matcher(string);
		if(m.find()){
			return true;
		}else{
			return false;
		}
	}
	
	private static boolean isSex(String string){
		String reString2 = "true|false";
		Pattern p = Pattern.compile(reString2);
		Matcher m = p.matcher(string);
		if(m.find()){
			return true;
		}else{
			return false;
		}
	}
	
	private static boolean isBirth(String string) {
//		String reString3 = "(^((19\\d{2})|(200\\d)|(201[0-7])))-?((0?[1-9]|1[0-2]))-?(((0[1-9])|([12][0-9])|(3[0-1])))$";
		String reString3 = "^((19\\d{2})|(200\\d)|(201[0-7]))-((0?[1-9])|(1[0-2]))-((0?[1-9])|([1-2]\\d)|(30))$";
		Pattern p = Pattern.compile(reString3);
		Matcher m = p.matcher(string);
		if(m.find()){
			return true;
		}else{
			return false;
		}
	}
}
